package com.gitee.dufafei.spark.pattern

import scala.util.control.Exception.ignoring

trait Borrow {

  type Closeable = { def close(): Unit }

  def using[R, T](resource: R)(execute: R => T)(implicit im: R => Closeable): T = {
    try {
      execute(resource)
    } finally {
      // ignoring(classOf[Throwable]) apply {resource.close()}
      ignoring(classOf[Throwable])(resource.close())
    }
  }
}
